<?php

App::uses('AppModel', 'Model');

abstract class Crud extends AppModel
{

    /**
     * Insertamos un registro
     * @param array $newData
     * @return array
     */
    final public function insert($newData) {
        if (isset($newData['id']) === false) {
            $newData['id'] = null;
        }
        $newRecord = $this->save($newData);
        return $newRecord;
    }

    /**
     * Actualizamos un registro
     * @param string $id
     * @param array $modifyData
     * @return array
     */
    final public function update($id, $modifyData) {
        $this->id = $id;
        return $this->save($modifyData);
    }

    /**
     * Deshabilitamos un registro
     * @param string $id
     * @param int $status
     * @return array
     */
    final public function destroy($id, $status) {
        $class = get_called_class();
        $this->id = $id;
        $record = $this->read();
        $record[$class]['status'] = $status;
        return $this->save($record[$class]);
    }

}
